package priv.mill.controller;


import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import priv.mill.model.User;

//项目/模块/方法路径
@Controller
@RequestMapping("/hello")
public class HelloController {
	
//	@RequestMapping(value="/{addr}/info",method=RequestMethod.POST,params= {"name","age!=10"},headers= {"User-Agent"})
	@GetMapping(value="/{addr}/info",headers= {"User-Agent"})
	
	public @ResponseBody String info(@PathVariable("addr") String abc,@RequestHeader("User-Agent") String ua) {
		return "<h1>这是一个 独立的Controller文件qqqxxc:"+ua+"</h1>";
	}
	@GetMapping("testcook")
	@ResponseBody
	public String cook(HttpServletRequest request) {
		Cookie[] cookies = request.getCookies();
		String cv="";
		for(Cookie  cookie:cookies) {
			if(cookie.getName().equals("JSESSIONID=FC42DA0432129D6885CB2183C031E5EA")) {
				cv =cookie.getValue();
			}
		}
		return cv;
	}
	@GetMapping("testcook2")
	public @ResponseBody String cook2(@CookieValue("JSESSIONID=FC42DA0432129D6885CB2183C031E5EA")String sv) {
		return sv;
	}
	
	@GetMapping("login")
	public @ResponseBody Object login(@Valid User user,Map<String, Object> map) {
		user.setName("刘德华");
		map.put("user", user);
		return "users";
	}
}

